const app = getApp()

Page({
  /**
   * 页面的初始数据
   */
  data: {
    currentTab: 0,
    lineFlag: false,
    winWidth: 0,
    winHeight: 0,
    scrollleft: 0,
    navHeight: null,
    animationData: {},
    openLineItem: [{ name: '会展中心' }, { name: '万里城', seat: '2.5km' }, { name: '检测中心' }, { name: '目的地1' }],
    openLineData: [
      {
        star: '汽贸城', end: '高铁线', time: '07:40', km: '2km', upTrain: '万科白马花园东门', nextTrain: ' 临空SOHO', butflag: true, lineflag: false,
        item: [{ name: '会展中心' }, { name: '万里城', seat: '2.5km' }, { name: '检测中心' }, { name: '目的地1' }]
      },
      {
        star: '汽车城', end: '虹桥线', time: '07:40', km: '3km', upTrain: '万科白马花园东门', nextTrain: ' 临空SOHO', butflag: false, lineflag: false,
        item: [{ name: '会展中心2' }, { name: '万里城', seat: '3.5km' }, { name: '检测中心' }, { name: '目的地2' }]
      },
      {
        star: '汽车城', end: '虹桥线', time: '07:40', km: '3km', upTrain: '万科白马花园东门', nextTrain: ' 临空SOHO', butflag: false, lineflag: false,
        item: [{ name: '会展中心2' }, { name: '万里城', seat: '3.5km' }, { name: '检测中心' }, { name: '目的地2' }]
      },
      {
        star: '汽车城', end: '虹桥线', time: '07:40', km: '3km', upTrain: '万科白马花园东门', nextTrain: ' 临空SOHO', butflag: false, lineflag: false,
        item: [{ name: '会展中心2' }, { name: '万里城', seat: '3.5km' }, { name: '检测中心' }, { name: '目的地2' }]
      },
      {
        star: '汽车城', end: '虹桥线', time: '07:40', km: '3km', upTrain: '万科白马花园东门', nextTrain: ' 临空SOHO', butflag: false, lineflag: false,
        item: [{ name: '会展中心2' }, { name: '万里城', seat: '3.5km' }, { name: '检测中心' }, { name: '目的地2' }]
      },
      {
        star: '汽车城', end: '虹桥线', time: '07:40', km: '3km', upTrain: '万科白马花园东门', nextTrain: ' 临空SOHO', butflag: false, lineflag: false,
        item: [{ name: '会展中心2' }, { name: '万里城', seat: '3.5km' }, { name: '检测中心' }, { name: '目的地2' }]
      },
      {
        star: '汽车城', end: '虹桥线', time: '07:40', km: '3km', upTrain: '万科白马花园东门', nextTrain: ' 临空SOHO', butflag: false, lineflag: false,
        item: [{ name: '会展中心2' }, { name: '万里城', seat: '3.5km' }, { name: '检测中心' }, { name: '目的地2' }]
      }
    ]
  },
  /** 
 * 滑动切换tab 
 */
  bindChange: function (e) {
    var that = this;
      that.setData({
        currentTab: e.detail.current
      });
      this.checkCor();
  },
  checkCor: function () {
    if (this.data.currentTab > 4) {
      this.setData({
        scrollleft: 300
      })
    } else {
      this.setData({
        scrollleft: 0
      })
    }
  },
  //动画 -- 滑出
  slideDown: function () {
    let _that = this
    _that.animation.translateY(450).step()
    _that.setData({
      animationData: _that.animation.export(),
    })
  },
  //禁止选项卡的左右滑动 
  stopTouchMove: function () {
    return false;
  },
  //动画 -- 滑入
  slideIn: function () {
    let _that = this
    _that.animation.translateY(0).step() // 在y轴偏移，然后用step()完成一个动画
    _that.setData({
      //动画实例的export方法导出动画数据传递给组件的animation属性
      animationData: _that.animation.export()
    })
  },
  /** 
   * 点击tab切换 
   */
  swichNav: function (e) {
    var that = this;
    if (that.data.currentTab === e.target.dataset.current) {
      return false;
    } else {
      that.setData({
        currentTab: e.target.dataset.current
      })
    }
  },
  openLine() {
    let _that = this
    _that.setData({
      lineFlag: true
    });
    // 创建动画实例
    var animation = wx.createAnimation({
      duration: 400,//动画的持续时间
      timingFunction: 'ease',//动画的效果 默认值是linear->匀速，ease->动画以低速开始，然后加快，在结束前变慢
    })
    _that.animation = animation; //将animation变量赋值给当前动画
    var time1 = setTimeout(function () {
      _that.slideIn();//调用动画--滑入
      clearTimeout(time1);
      time1 = null;
    }, 100)
  },
  colseLine() {
    var _that = this;
    var animation = wx.createAnimation({
      duration: 400,//动画的持续时间 默认400ms
      timingFunction: 'ease',//动画的效果 默认值是linear
    })
    _that.animation = animation
    _that.slideDown();//调用动画--滑出
    var time1 = setTimeout(function () {
      _that.setData({
        lineFlag: false
      })
      clearTimeout(time1);
      time1 = null;
    }, 220)//先执行下滑动画，再隐藏模块

  },
  bookLine() {
    wx.navigateTo({
      url: '/pages/routedetails/routedetails',
    })
  },
  /**
  * 生命周期函数--监听页面加载
  */
  onLoad: function (options) {
    var that = this;
    /** 
     * 获取系统信息 
     */
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          winWidth: res.windowWidth,
          winHeight: res.windowHeight,
          navHeight: app.globalData.navHeight + 1,
        });
      }

    });
  },
});